package com.utils;

/**
 * 将驼峰格式的字符串转换为大写的常量字段的格式 如：goodReport 转化后是GOOD_REPORT
 *
 * 
 */
public class ToCamelCaseUtil {
  public static String toCamelCase(String str) {
    int len = str.length();
    StringBuilder sb = new StringBuilder(len + 20);
    char c;
    for (int i = 0; i < len; i++) {
      c = str.charAt(i);
      if (c >= 'A' && c <= 'Z') {
        sb.append('_').append(c);
      } else if (c >= 'a' && c <= 'z') {
        sb.append((char) (c - 32));
      } else {
        sb.append(c);
      }
    }
    return sb.toString();
  }
}
